/*
 * @(#)SSEControl.java 1.0 2005-3-10
 * Copyright 2005 VandaGroup, Inc. All rights reserved.
 */
package com.vanda.log;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;

import com.vanda.data.UserInfoValueObject;
import com.vanda.util.ServiceLocator;
/*******
 * 类说明:
 * 控制类
 * <P>@author 蒋勇
 * <P>@version 1.0 2005-3-10
 */
public class LogControl { 
	/**
	 * 方法说明:
	 * 记录日志
	 * @param object
	 * @param userBean
	 * @author 蒋勇 2005-4-11
	 */
	public static void writeLog(Object object, UserInfoValueObject userBean) {
		LogObject _logObject = new LogObject(userBean, object);
		QueueSession session = null;
		QueueConnection connection = null;
		try {
			// Create a QueueConnection from the QueueConnectionFactory
			connection =
				((QueueConnectionFactory) ServiceLocator
					.getInstance()
					.getEJBHome("jms/CfiConnectionFactory"))
					.createQueueConnection();
			connection.start();
			// QueueSession: Not transacted, and acknowledge received messages
			boolean transacted = false;
			session =
				connection.createQueueSession(
					transacted,
					Session.AUTO_ACKNOWLEDGE);
			QueueSender queueSender =
				session.createSender(
					(Queue) ServiceLocator.getInstance().getEJBHome(
						"jms/CfiLogQueue"));
			ObjectMessage outMessage = session.createObjectMessage(_logObject);
			queueSender.send(outMessage);
			queueSender.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (session != null) {
					session.close();
					session = null;
				}
				if (connection != null) {
					connection.close();
					connection = null;
				}
			} catch (JMSException e) {
				e.printStackTrace();
			}
		}
	}
}
